/**
 * Created by isoft-work 5 on 1/3/2015.
 */
$(document).ready(function(){
//   render
   getAllBillOrderUser(CheckBillPage.idHD, CheckBillPage.email);
//   event
});

function getAllBillOrderUser(idHD, eMail) {
   ISS.BACKEND.request({
      url: ISS.SESSION.getSession('contextPath') + '/service/EditAccount/getDetailBillPopup/' + idHD + '/' + eMail + '.',
      headers: {
         'Accept': 'application/json',
         'Content-Type': 'application/json'
      },
      type: 'POST',
      dataType: 'json',
      success: function (data) {
         var responseInfo = data.responseObject;
         getAllBillOrderUserComplete(responseInfo);
      }
   });
}

function getAllBillOrderUserComplete(bill) {
   if(bill) {
      generaDataBillOrder(bill);
      var html = ISS.TEMPLATE.handleBar.renderByString(TEMPLATE.CheckBillOrder.page, bill);
      ISS.DOM.html('#cart-items-list-form', html);
   }
   else {
      alert('Không tìm thấy hoá đơn !');
   }
}

function generaDataBillOrder(bill) {
   var lstDetailBill = bill.chiTietHoaDon;
   for(var i = 0; i < lstDetailBill.length; i++) {
      lstDetailBill[i].tongGiaBan = ISS.STRING_UTIL.formatNumeral(lstDetailBill[i].tongGia * lstDetailBill[i].soLuong, '0,0');
      lstDetailBill[i].tongGia = ISS.STRING_UTIL.formatNumeral( lstDetailBill[i].tongGia, '0,0');
      if(lstDetailBill[i].chiTietSanPham.hinhAnhSanPham.length > 0) {
         lstDetailBill[i].image = ISS.SESSION.getSession('contextPath') + lstDetailBill[i].chiTietSanPham.hinhAnhSanPham[0].tenHinh;
         lstDetailBill[i].tenSP = lstDetailBill[i].chiTietSanPham.hinhAnhSanPham[0].chiTietSanPham.sanPham.tenSP;
      }
   }
   bill.tongTien = ISS.STRING_UTIL.formatNumeral(bill.tongTien, '0,0');
}
